package com.yj.springbootstudy.mulThread.imooc.juctools;

import java.util.Random;
import java.util.concurrent.CountDownLatch;

/**
 * CountDownLatch
 */
public class CountDownLatchTest {

    private static int threadCount = 5;
    private static CountDownLatch countDownLatch = new CountDownLatch(threadCount);

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 5 ; i++) {
            int finalI = i;
            new Thread(()->{
                System.out.println(finalI +"处理报表");
                try {
                    Thread.sleep(new Random().nextInt(5000));
                    System.out.println(finalI + "处理完毕");
                    countDownLatch.countDown();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            },i+"").start();
        }
        countDownLatch.await();
        System.out.println("报表全部处理完成！执行其他操作！");

    }
}
